package com.itcode.validation;

import com.itcode.anno.State;
import jakarta.validation.ConstraintValidator;
import jakarta.validation.ConstraintValidatorContext;

public class StateValidation implements ConstraintValidator<State, String> {
    //ConstraintValidator<State, String>,State表示给哪个注解添加校验规则，String表示校验的数据类型

    /**
     * @param s                          将来要校验的数据
     * @param constraintValidatorContext
     * @return
     */
    @Override
    public boolean isValid(String s, ConstraintValidatorContext constraintValidatorContext) {
        //提供校验规则
        if (s == null) {
            return false; //校验不通过
        }

        if (s.equals("已发布") || s.equals("草稿")) {
            return true;
        }
        return false;
    }
}
